package com.api.shopapi.mapper;


import com.api.shopapi.entity.Role;
import com.api.shopapi.entity.dto.RoleDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface RoleMapper {

    @Insert("insert into role values(#{role.RoleCode},#{role.Name},#{role.Sort})")
    public int insert(@Param("role") Role role);


    @Delete("delete from role where roleCode=#{roleCode}")
    public int deleteByRoleCode(@Param("roleCode") String roleCode);


    @Update("update role set Name=#{role.Name},Sort=#{role.Sort} " +
            "where RoleCode=#{role.RoleCode}")
    public int updateByRoleCode(@Param("role") Role role);


    @Select("select * from role where roleCode=#{roleCode} limit 1")
    public Role getByRoleCode(@Param("roleCode") String roleCode);

    @Select("select * from role where name=#{name} limit 1")
    public Role getByName(@Param("name") String name);


    @Select("select * from role order by Sort desc")
    public List<Role> getList();

    @Select("select * from role order by Sort desc")
    public List<RoleDTO> getListDTO();

}
